﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ext.Net;

public partial class SYS_POPEDOM_DropDownList_Manage : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            AddTabForMaster();
        }
    }
    private void AddTabForMaster()
    {
        string Url = G_Url_allstring + "/SYS_BASEINFO/DropDownList_Create.aspx";
        String tabid = Request.QueryString["tabid"];
        extBtn_Add.Listeners.Click.Handler = "popfortab(GridPanel1,'" + Url + "','ObjId','Add',0,'','" + tabid + "','下拉项增加',1)";
        extBtn_Edit.Listeners.Click.Handler = "popfortab(GridPanel1,'" + Url + "','ObjId','DROPDOWN_NAME',0,'','" + tabid + "','下拉项编辑',2)";
        GridPanel1.Listeners.RowDblClick.Handler = "popfortab(GridPanel1,'" + Url + "','ObjId','DROPDOWN_NAME',rowIndex,'','" + tabid + "','下拉项编辑',3)";

    }
    protected void OnStoreRefreshData(object sender, StoreRefreshDataEventArgs e)
    {
        BindData();
    }
    private void BindData()
    {
        DataTable tmpDT = CommonLib.BLL.BS_DROPDOWN.GetList(GetQuery()).Tables[0];
        this.Store1.DataSource = tmpDT;
        this.Store1.DataBind();
    }

    private string GetQuery()
    {
        string strWhere = "1=1";
        if (exttxtf_dropdown_name.Text != "")
            strWhere += " and dropdown_name like '%" + exttxtf_dropdown_name.Text + "%'";
        if (extcomb_select_type.SelectedItem.Text != "")
            strWhere += " and select_type=" + int.Parse(extcomb_select_type.SelectedItem.Value);
        if (extcomb_data_source.SelectedItem.Text != "")
            strWhere += " and data_source=" + int.Parse(extcomb_data_source.SelectedItem.Value);
        return strWhere;
    }
    protected void OnBtnSearchClick(object sender, DirectEventArgs e)
    {
        BindData();
    }
    protected void extBtn_Delete_Click(object sender, DirectEventArgs e)
    {
        int nCount = 0;
        RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
        nCount = sm.SelectedRows.Count;
        if (nCount == 0)
        {
            X.Msg.Alert("系统提示", "请先选择要删除的记录！").Show();
            return;
        }

        X.Msg.Confirm("系统提示", "是否删除选中行?", new MessageBoxButtonsConfig
        {
            Yes = new MessageBoxButtonConfig
            {
                Handler = "Ext.net.DirectMethods.DoDelRows();",
                Text = "是"
            },
            No = new MessageBoxButtonConfig
            {

                Text = "否"
            }
        }).Show();

    }

    //删除行


    [DirectMethod]
    public void DoDelRows()
    {
        RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
        DataTable dtt = null;
        foreach (SelectedRow row in sm.SelectedRows)
        {
            dtt = CommonLib.BLL.BS_DROPDOWN.GetList("dropdown_name='" + row.RecordID.Trim() + "'").Tables[0];
            if (dtt.Rows[0]["data_type"].ToString() == "2")
                CommonLib.BLL.BS_DROPDOWN.Delete(row.RecordID.Trim());
        }
        BindData();
    }
    protected void extBtn_Refresh_Click(object sender, DirectEventArgs e)
    {
        BindData();
    }
    protected void ClearDataEvent(object sender, DirectEventArgs e)
    {
        exttxtf_dropdown_name.Text = "";
        extcomb_select_type.SelectedIndex = 0;
        extcomb_data_source.SelectedIndex = 0;
    }
}
